<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */

/**
 * Replace cached inserts with the actual results
 *
 * @param string $results
 * @return string
 */
function smarty_insert_product_vh_products($params, &$smarty) {
	//global $pObj;
	
	//
	//$_SESSION['vh']->add($product['products_id'], 'p');
	//$vh_products = $pObj->getProducts(array('ids' => $_SESSION['vh']->get('p')));
	if( $smarty->caching == 1 ) {
		$smarty->caching = 0;
		
		$vh_ids = $_SESSION['vh']->get('p', 4);
		if( is_array($vh_ids) ) {
			global $pObj;
			/*
			$pObj->logQueryLimit();
			$pObj->setQueryLimitLength(6);
			$vh_products = $pObj->getProducts(array('ids' => $vh_ids));
			$pObj->resetQueryLimit();
			
			$vh_products = $pObj->setListKey($vh_products, 'products_id');
			foreach($vh_ids as $k => $v) {
				$vh_products_b[] = $vh_products[$v];	
			}
			$vh_products = $vh_products_b;
			unset($vh_products_b);
			
			include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'product.application.class.php');
			include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'product.application.data.class.php');
			$pappdObj = new ProductApplicationDataBase();
			$vh_products = $pappdObj->getProductsApplications($vh_products, 5, true);
			*/
			//
			$pObj->logQueryLimit();
			foreach($vh_ids as $k => $v) {
				$vh_products[] = $pObj->cache('getProduct', array($v));
			}
			include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'product.application.class.php');
			include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'product.application.data.class.php');
			$pappdObj = new ProductApplicationDataBase();
			$vh_products = $pappdObj->getProductsApplications($vh_products, 5, true);
		}
		
		$smarty->set_vars_content('vh_products', $vh_products);
		$content = $smarty->fetch($params['file']);
		$smarty->caching = 1;
	} else {
		$vh_ids = $_SESSION['vh']->get('p', 4);
		if( is_array($vh_ids) ) {
			global $pObj;
			
			$pObj->logQueryLimit();
			$pObj->setQueryLimitLength(6);
			$vh_products = $pObj->getProducts(array('ids' => $vh_ids));
			$pObj->resetQueryLimit();
			
			$vh_products = $pObj->setListKey($vh_products, 'products_id');
			foreach($vh_ids as $k => $v) {
				$vh_products_b[] = $vh_products[$v];	
			}
			$vh_products = $vh_products_b;
			unset($vh_products_b);
			
			include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'product.application.class.php');
			include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'product.application.data.class.php');
			$pappdObj = new ProductApplicationDataBase();
			$vh_products = $pappdObj->getProductsApplications($vh_products, 5);
		}
		
		$smarty->set_vars_content('vh_products', $vh_products);
		$content = $smarty->fetch($params['file']);
	}
	
	return $content;
}
//
?>